    package com.ktjy.springsecuitydemo.controller;

    import org.springframework.security.access.annotation.Secured;
    import org.springframework.security.access.prepost.PreAuthorize;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;

    @Controller
    public class LoginController {

        @GetMapping("/tologin")
        public String toLogin() {
            return "login";
        }

        // 负责登录成功后跳转到主页面
        //在UserDetailsSericeImpl 中为登录用户添加过名为 "ROLE_abc" 的权限
    //    @Secured("ROLE_abc")
        //访问这个方法之前判断当前登录用户是否有"ROLE_abc" 角色权限
        @PreAuthorize("hasRole('abc')")
        @RequestMapping("/toMain")
        public String toMain() {
            return "main";
        }

        @RequestMapping("/toError")
        public String toError() {
            return "error";
        }

        @GetMapping("/toMain1")
        public String toMain1() {
            return "main1";
        }

        //负责跳转到demo.html页面
        @GetMapping("/demo")
        public String demo() {
            return "demo";
        }
    }
